<script setup lang="ts">
import { ref } from "vue";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import { usePublicHooks } from "../../../hooks";

const props = withDefaults(defineProps<FormProps>(), {
  id: String, // 添加 id prop
  formInline: () => ({
    id: "",
    push_base_url: "",
    access_key: "",
    access_password: "",
    much_id: "",
    status: 0,
    payment_method: 1,
    money: 0
  })
});

const ruleFormRef = ref();
const { switchStyle } = usePublicHooks();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="82px"
  >
    <el-form-item label="推送url" prop="push_base_url">
      <el-input
        v-model="newFormInline.push_base_url"
        clearable
        placeholder="请输入推送url"
      />
    </el-form-item>

    <el-form-item label="Key值" prop="access_key">
      <el-input
        v-model="newFormInline.access_key"
        clearable
        placeholder="请输入Key值"
      />
    </el-form-item>

    <el-form-item label="密码" prop="access_password">
      <el-input
        v-model="newFormInline.access_password"
        clearable
        placeholder="请输入密码"
      />
    </el-form-item>

    <el-form-item label="商户id" prop="much_id">
      <el-input
        v-model="newFormInline.much_id"
        clearable
        placeholder="请输入商户id"
      />
    </el-form-item>
    <el-form-item label="余额(分)" prop="money">
      <el-input-number
        v-model="newFormInline.money"
        class="!w-full"
        :min="0"
        :max="999999"
        controls-position="right"
      />
    </el-form-item>

    <el-form-item label="状态">
      <el-switch
        v-model="newFormInline.status"
        inline-prompt
        :active-value="1"
        :inactive-value="0"
        active-text="启用"
        inactive-text="停用"
        :style="switchStyle"
      />
    </el-form-item>
    <el-form-item label="支付类型">
      <el-switch
        v-model="newFormInline.payment_method"
        inline-prompt
        :active-value="1"
        :inactive-value="2"
        active-text="全额付款"
        inactive-text="部分支付"
        :style="switchStyle"
      />
    </el-form-item>
  </el-form>
</template>
